﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Talentnet.Core.Database;
using Talentnet.Data.Entity;
using System.Data;

namespace Talentnet.Data.Access
{
    partial class LoginUserDAL
    {
        public int UserChangePwd(Guid userRecID, string curPwd, string newPwd)
        {
            DataTable tb = _dbProvider.ExecDataTable("spa_SEC_ChangeUserPassword", userRecID, curPwd, newPwd);
            return (int)tb.Rows[0][0];
        }
        public void CreateForgotPwdRequest(Guid userRecID, string validKey)
        {
            _dbProvider.ExecCommand("spa_SEC_CreateForgotPwdRequest", userRecID, validKey);
        }
        public int ValidateForgotPwdRequest(Guid userRecID, string validKey, string remoteIP)
        {
            DataTable tb = _dbProvider.ExecDataTable("spa_SEC_ValidateForgotPwdRequest", userRecID, validKey, remoteIP, "", "");
            return (int)tb.Rows[0][0];
        }
        public DataTable GetUserMenus(Guid userRecID)
        {
            return _dbProvider.ExecDataTable("spa_SEC_GetMenuItemForUser", userRecID);
        }
        public DataTable GetUserRoles(Guid userRecID)
        {
            return _dbProvider.ExecDataTable("spa_SEC_GetRolesForUser", userRecID);
        }
        public DataTable GetUserPermissions(Guid userRecID)
        {
            return _dbProvider.ExecDataTable("spa_SEC_GetUserPermissions", userRecID);
        }
        public int UserLogin(int clientID, string username, string password, string remoteIP)
        {
            DataTable tb = _dbProvider.ExecDataTable("spa_SEC_Login", clientID, username, password, remoteIP, "", "");
            return (int)tb.Rows[0][0];
        }
        
        public LoginUser GetUserDetail(int clientID, string username)
        {
            DataTable tb = _dbProvider.ExecDataTable("spa_SEC_GetUser", null, username, clientID);
            if (tb.Rows.Count > 0)
            {
                return LoginUser.CreateEntity(tb.Rows[0]);
            }
            return null;
        }
        public LoginUser GetUserDetail(Guid userRecID)
        {
            DataTable tb = _dbProvider.ExecDataTable("spa_SEC_GetUser", userRecID, null, null);
            if (tb.Rows.Count > 0)
            {
                return LoginUser.CreateEntity(tb.Rows[0]);
            }
            return null;
        }
        
    }
}
